import 'package:excel_utils/extend/string_extend.dart';
import 'package:flutter/material.dart';

TableRow tabRows(List<String> tabLabels, {int? maxLines, double? fontSize}) {
  return TableRow(
      children:
          tabLabels.map((e) => TableCell(child: Text(e, style: TextStyle(fontSize: fontSize), textAlign: TextAlign.center, maxLines: maxLines))).toList());
}

// 表Widget
TableRow tabRowWidgets(List<Widget> tabLabels) {
  return TableRow(
      children: tabLabels
          .map((e) => TableCell(
                  child: Container(
                child: e,
                alignment: Alignment.center,
              )))
          .toList());
}

Widget copyWidget(Widget text) {
  return InkWell(
    onTap: () {
      (text as Text).data?.copyValue();
    },
    child: text,
  );
}

// 日期范围
// Widget calendarDatePicker({
//   required year,
//   required month,
//   required day,
//   bool row = false,
//   DateTime? currentStartDate,
//   DateTime? currentEndDate,
//   required Function(String) startOnDateChanged,
//   required Function(String) endOnDateChanged,
// }) {
//   Widget startWidget = SizedBox(
//     width: 300,
//     height: 200,
//     child: CalendarDatePicker(
//         initialDate: null,
//         currentDate: currentStartDate ?? DateTime(year, month, day - 1, 00, 00, 00),
//         firstDate: DateTime(2020 - 10, 1, 1, 0, 0, 0),
//         lastDate: DateTime(year, month, day - 1, 23, 59, 59),
//         onDateChanged: (date) {
//           var startTime = "${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')} 00:00:00";
//           startOnDateChanged(startTime);
//         }),
//   );
//   Widget endWidget = SizedBox(
//     width: 300,
//     height: 200,
//     child: CalendarDatePicker(
//         initialDate: null,
//         currentDate: currentEndDate ?? DateTime(year, month, day - 1, 59, 59, 59),
//         firstDate: DateTime(2020 - 10, 1, 1, 0, 0, 0),
//         lastDate: DateTime(year, month, day - 1, 23, 59, 59),
//         onDateChanged: (date) {
//           var endTime = "${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')} 23:59:59";
//           endOnDateChanged(endTime);
//         }),
//   );
//   if (row) {
//     return Row(children: [startWidget, endWidget]);
//   } else {
//     return Column(children: [startWidget, endWidget]);
//   }
// }

Widget calendarDatePicker(
    {year,
    month,
    day,
    bool row = false,
    DateTime? currentStartDate,
    DateTime? currentEndDate,
    required Function(String, DateTime) startOnDateChanged,
    required Function(String, DateTime?) endOnDateChanged}) {
  Widget startWidget = SizedBox(
    width: 280,
    height: 200,
    child: CalendarDatePicker(
        initialDate: null,
        currentDate: currentStartDate ?? DateTime(year, month, day - 1, 00, 00, 00),
        firstDate: DateTime(2024, 1, 1, 0, 0, 0),
        lastDate: DateTime(2030, 1, 1, 23, 59, 59),
        onDateChanged: (date) {
          String monthStr = date.month.toString().padLeft(2, '0');
          String dayStr = date.day.toString().padLeft(2, '0');
          String startTime = "${date.year}-${monthStr}-${dayStr} 00:00:00";
          startOnDateChanged(startTime, date);
        }),
  );
  Widget endWidget = SizedBox(
    width: 280,
    height: 200,
    child: CalendarDatePicker(
        initialDate: null,
        currentDate: currentEndDate ?? DateTime(year, month, day - 1, 59, 59, 59),
        firstDate: DateTime(2024, 1, 1, 0, 0, 0),
        lastDate: DateTime(2030, 1, 1, 23, 59, 59),
        onDateChanged: (date) {
          String monthStr = date.month.toString().padLeft(2, '0');
          String dayStr = date.day.toString().padLeft(2, '0');
          String endTime = "${date.year}-${monthStr}-${dayStr} 23:59:59";
          endOnDateChanged(endTime, date);
        }),
  );
  if (row) {
    return Row(children: [startWidget, endWidget]);
  } else {
    return Column(children: [startWidget, endWidget]);
  }
}
